package thread;

/**
 * Created by wangxingsheng on 2021/3/4.
 */
public class ThreadTest {
    public static void main(String[] args) {
        Thread thread01 = new MyThread("thread01");
        Thread thread02 = new MyThread("thread02----",2);
        Thread thread03 = new MyThread("thread03----------");
        thread01.start();
        thread02.start();
        thread03.setDaemon(true);
        thread03.start();
    }

    static class MyThread extends Thread {
        private int sleep = -1;
        MyThread(String name) {
            super(name);
        }

        MyThread(String name,int sleep) {
            super(name);
            this.sleep = sleep;
        }

        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                if(sleep != -1){
                    try {
                        Thread.sleep(sleep*1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println(getName() + " - " + i);
            }
            System.out.println(getName() + " over");
        }
    }
}
